/*
 * Copyright (C) 2011-present ShenZhen iBOXCHAIN Information Technology Co.,Ltd.
 *
 * All right reserved.
 *
 * This software is the confidential and proprietary
 * information of iBOXCHAIN Company of China.
 * ("Confidential Information"). You shall not disclose
 * such Confidential Information and shall use it only
 * in accordance with the terms of the contract agreement
 * you entered into with iBOXCHAIN inc.
 */
package com.example.wac.shiro.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author wuancheng
 * @description
 * @date 2023-04-14 18:25:00
 */

public class RedisMsgProducer {
    private static Logger log = LoggerFactory.getLogger(RedisMsgProducer.class);
    private JedisPool jedisPool;

    public RedisMsgProducer() {
    }

    public boolean sendMsg(String message, String[] channels) {
        Jedis jedis = null;

        try {
            if (channels != null && channels.length > 0) {
                jedis = this.getJedisPool().getResource();
                String[] var7 = channels;
                int var6 = channels.length;

                for(int var5 = 0; var5 < var6; ++var5) {
                    String channel = var7[var5];
                    jedis.publish(channel, message);
                }

                return true;
            }
        } catch (Exception var11) {
            log.error("redis发送数据异常：", var11);
        } finally {
            if (jedis != null) {
                jedis.close();
            }

        }

        return false;
    }

    public boolean sendMsg(String message) {
        Jedis jedis = null;

        try {
            jedis = this.getJedisPool().getResource();
            jedis.publish("channel:refresh:url:perms", message);
            return true;
        } catch (Exception var7) {
            log.error("redis发送数据异常：", var7);
        } finally {
            if (jedis != null) {
                jedis.close();
            }

        }

        return false;
    }

    public JedisPool getJedisPool() {
        return this.jedisPool;
    }

    public void setJedisPool(JedisPool jedisPool) {
        this.jedisPool = jedisPool;
    }
}
